package com.novoda.runbuddy.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageButton;

import com.novoda.runbuddy.R;
import com.novoda.runbuddy.activity.stopwatch.RemoteStopClockProxy;
import com.novoda.runbuddy.controller.HomeControllerImpl;
import com.novoda.runbuddy.controller.IHomeController;
import com.novoda.runbuddy.controller.IOptionsMenu;
import com.novoda.runbuddy.controller.OptionsMenuImpl;

public class Home extends Activity {

	private IHomeController	homeController;
	private IOptionsMenu	optionsMenu;
	
	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.home);
		optionsMenu = new OptionsMenuImpl(this);
		homeController = new HomeControllerImpl(this);

		homeController.createHomeView(this,
				(ImageButton) findViewById(R.id.goto_stopwatch),
				(ImageButton) findViewById(R.id.goto_today));

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		optionsMenu.addAllActivitiesToMenu(menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		optionsMenu.selectItem(item);
		return super.onOptionsItemSelected(item);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		return homeController.onKeyDown(keyCode, event);
	}

	@Override
	protected void onStop() {
		super.onStop();
		RemoteStopClockProxy.getInstance().unregisterListener(this);
	}

	@Override
	protected void onStart() {
		super.onStart();
		RemoteStopClockProxy.getInstance().registerListener(this);
	}

}